local wuqian = fk.CreateSkill {

  name = "joy__wuqian",

  tags = { Skill.Compulsory, },

}



wuqian:addEffect(fk.TargetSpecified, {
  name = "joy__wuqian",
  events = {fk.TargetSpecified},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if data.card.trueName == "slash" then
      return target == player and player:hasSkill(wuqian.name) and  player:usedCardTimes("slash") <= 1 and data.firstTarget
    elseif  data.card.trueName == "duel" then
      return target == player and player:hasSkill(wuqian.name) and player:usedCardTimes("duel") <= 1 and data.firstTarget
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      card_event.joy__wuqian_armor = true
      room:addPlayerMark(room:getPlayerById(data.to), fk.MarkArmorNullified)
      if not player:hasSkill("wushuang") then
        room:handleAddLoseSkills(player, "wushuang", nil, true, false)
        room:addPlayerMark(player, "wuqian_wushuang")
      end
  end,
})
wuqian:addEffect(fk.CardUseFinished, {
  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    if player ~= target then return false end
    local card_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    return card_event and card_event.joy__wuqian_armor
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      room:removePlayerMark(p, fk.MarkArmorNullified, num)
    end
    if player:getMark("wuqian_wushuang") == 1 then
        room:handleAddLoseSkills(player, "-wushuang", nil, true, false)
        room:removePlayerMark(player,"wuqian_wushuang")
    end
  end,
})

return wuqian